# -*- coding: utf-8 -*-
"""
@File: kline.py.py
@author: chenxialin
@time: 9月 26, 2025 20:39
"""
# models/kline.py
from sqlalchemy import Column, Integer, String, Float, BigInteger, DECIMAL
from mysql.database import Base

class Kline(Base):
    __tablename__ = "kline"

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    code = Column(String(20), nullable=False, comment="股票代码")
    date = Column(BigInteger, nullable=False, comment="日期 年月日（东财K线数据 索引0）")
    open = Column(DECIMAL(10, 2), nullable=False, comment="开盘价")
    close = Column(DECIMAL(10, 2), nullable=False, comment="收盘价")
    high = Column(Float, nullable=False, comment="最高价（索引3）")
    low = Column(Float, nullable=False, comment="最低价（索引4）")
    volume = Column(Float, nullable=False, comment="成交量（索引5）")
    amount = Column(Float, nullable=False, comment="成交额（索引6）")
    amplitude = Column(Float, nullable=False, comment="振幅（索引7）")
    chg = Column(Float, nullable=False, comment="涨跌幅（索引8）")
    change = Column(Float, nullable=False, comment="涨跌额（索引9）")
    turn = Column(Float, nullable=False, comment="换手率（索引10）")

    def __repr__(self):
        return f"<Kline(code='{self.code}', date={self.date}, close={self.close})>"